package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"news_sys/models"
)

type TypeController struct {
	beego.Controller
}

func (c *TypeController) Create() {
	c.Ctx.Output.Header("Access-Control-Allow-Origin", "*")
	c.Ctx.Output.Header("Access-Control-Allow-Methods", "*")
	c.Ctx.Output.Header("Access-Control-Allow-Headers", "*")
	if c.Ctx.Input.Method() == "OPTIONS" {
		c.Ctx.Output.SetStatus(200)
		c.StopRun()
	}
	var Type models.Type
	Type.TypeName = c.GetString("name")
	if models.DB.Create(&Type).Error != nil {
		c.Data["json"] = map[string]any{
			"Code": 500,
			"Msg":  "服务器繁忙",
		}
		c.ServeJSON()
		return
	}
	c.Data["json"] = map[string]any{
		"Code": 200,
		"Msg":  "上传成功",
	}
	c.ServeJSON()
}
